 /*
 * @description: 收入统计-商城佣金
 * @Author: along
 * @Date: 2021-06-05
 * @Last Modified by: along
 * @Last Modified time: 2021-06-05
 */
<template>
    <div class="container studentCommissionFirst">

        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">收入名称:</p>
                    <el-select
                        v-model="type"
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in typeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
            </div>
            <div class="header-right">
                <div class="header-new-box">
                    <p class="__info_title">
                        所得分佣统计：
                        <span>
                            ¥{{ shop_total_income ? shop_total_income.toFixed(2) : '0.00' }}
                        </span>
                    </p>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="studentCommissionFirst"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="true_name"
                label="粉丝用户信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="190"
            >
                <template slot-scope="scope">
                    <div class="__zsdx_wrap">
                        <div class="__top">
                            <p class="__top_name">
                                {{ scope.row.true_name }}
                            </p>
                            <img
                                v-if="scope.row.agent_no"
                                class="__top_logo"
                                src="http://cdn.zsdx.cn/student-app/images/stuagent.png"
                            >
                        </div>
                        <div class="__phone">手机号：{{ scope.row.phone }}</div>
                        <div class="__id">用户ID：{{ scope.row.student_no }}</div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="agent_level"
                label="精英等级"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.agent_level | filterLevel }}
                </template>
            </el-table-column>
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="aim_type"
                label="收入名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.aim_type | filterType }}
                </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="下单时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="rebate_time"
                label="实际到账时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.rebate_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="ori_money"
                label="订单实付金额"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    ¥{{ scope.row.ori_money ? scope.row.ori_money : '0.00' }}
                </template>
            </el-table-column>
            <el-table-column
                prop="rebate_money"
                label="实际所得分佣"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    ¥{{ scope.row.rebate_money ? (Number(scope.row.rebate_money).toFixed(2)) : '0.00' }}
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

    </div>
</template>

<script>
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    props: {
        agent_no: {
            type: String,
            default: ''
        },
        shop_total_income: {
            type: Number,
            default: 0
        },
        start_time: {
            type: Number,
            default: 0
        },
        end_time: {
            type: Number,
            default: 0
        }
    },
    data () {
        return {
            type: 99,
            typeList: [
                {value: 99,label: '全部'},
                {value: 1,label: '直属订单收益'},
                {value: 2,label: '团队订单收益'},
                /*{value: 3,label: '商品类目代理分佣'},
                {value: 4,label: '店铺代理分佣'},
                {value: 5,label: '掌大分佣'},
                {value: 6,label: '掌大员工分佣'},*/
                {value: 7,label: '自购订单收益'},
            ],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {
        filterType (val) {
            if(val === 1) return '直属订单收益';
            if(val === 2) return '团队订单收益';
            if(val === 3) return '商品类目代理分佣';
            if(val === 4) return '店铺代理分佣';
            if(val === 5) return '掌大分佣';
            if(val === 6) return '掌大员工分佣';
            if(val === 7) return '自购订单收益';
            return '--';
        },
        filterLevel (val) {
            if(val === -1) return '--';
            if(val === 0) return 'E0';
            if(val === 1) return 'E1';
            if(val === 2) return 'E2';
            if(val === 3) return 'E3';
            if(val === 4) return 'E4';
            if(val === 5) return 'E5';
            if(val === 6) return 'E6';
            return '--';
        }
    },
    computed: {},
    watch: {
        start_time (val) {
            this.getTableData();
        },
        end_time (val) {
            this.getTableData();
        },
        agent_no (val) {
            this.getTableData(1);
        }
    },
    mounted () {
        this.authResult = this.$route.meta.authResult;

        setTimeout(() => {
            this.getTableData(1);
        }, 100);
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/stuagent_rebate%5Cget_shop_total_income_list', {
                page_id: page || this.page.now_page,
                type: this.type,
                agent_no: this.agent_no,
                start_time: this.start_time,
                end_time: this.end_time,
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 24px 32px 12px 32px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 24px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
                .__info_title {
                    display: flex;
                    align-items: center;
                    color: rgba(51, 51, 51, 1);
                    font-size: 14px;
                    span {
                        color: rgba(255, 142, 57, 1);
                        font-weight: 500;
                        font-size: 14px;
                    }
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }

    .__zsdx_wrap {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        .__top {
            display: flex;
            align-items: center;
            .__top_name {
                color: rgba(51, 51, 51, 1);
                font-size: 14px;
                font-weight: 500;
                margin-right: 6px;
            }
            .__top_logo {
                width: 28px;
                height: 14px;
            }
        }
        .__phone {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
            margin-top: 7px;
            margin-bottom: 5px;
        }
        .__id {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
        }
    }

    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
</style>
<style lang="less">
    .studentCommissionFirst{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>
